
package core.schedule.snake.schedule.core;

import org.quartz.CronExpression;
import org.quartz.CronTrigger;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

import core.tool.common.StringHelper;



public class CronTriggerRunner {

    public void task(Job job,String cronExpression) throws SchedulerException
    {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();
        long ctime = System.currentTimeMillis(); 
        JobDetail jobDetail = new JobDetail(StringHelper.getUUID(), StringHelper.getUUID(), job.getClass());
        jobDetail.getJobDataMap().put("JOB", job);
        CronTrigger cronTrigger = new CronTrigger(StringHelper.getUUID(), StringHelper.getUUID());
        try {
            CronExpression cexp = new CronExpression(cronExpression);
            cronTrigger.setCronExpression(cexp);
            scheduler.scheduleJob(jobDetail, cronTrigger);
            scheduler.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
